###############################################################################
# Copyright (C), 2024, Jiangsu Dongcheng M&E Tools Co., Ltd
# Author:	limin.wang
# Date:		2024/02/22
# Note:		
###############################################################################

project(node_camdar1)

set(CMAKE_CXX_STANDARD 17)
add_definitions(-Wall)

### --------------------------------------------------------------------
### Source code
### --------------------------------------------------------------------
file(GLOB_RECURSE H_FILES "${CMAKE_CURRENT_LIST_DIR}/*.h")
file(GLOB_RECURSE C_FILES "${CMAKE_CURRENT_LIST_DIR}/*.c")
file(GLOB_RECURSE CC_FILES "${CMAKE_CURRENT_LIST_DIR}/*.cc")
file(GLOB_RECURSE CPP_FILES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")

set(COMPILE_FILES ${H_FILES} ${C_FILES} ${CC_FILES} ${CPP_FILES})


### --------------------------------------------------------------------
### Generate lib
### --------------------------------------------------------------------
add_library(${PROJECT_NAME} SHARED ${COMPILE_FILES})

target_include_directories(${PROJECT_NAME} PRIVATE
        ${CMAKE_CURRENT_LIST_DIR}/src
        $ENV{ROS_PATH}/include/
        ${CMAKE_SOURCE_DIR}/lib/3rd/${BUILD_PLATFORM}/include
)

if (${BUILD_PLATFORM} STREQUAL "arm")
    target_compile_definitions(${PROJECT_NAME} PRIVATE -DSPDLOG_FMT_EXTERNAL)
endif ()

target_link_directories(${PROJECT_NAME} PRIVATE
        $ENV{ROS_PATH}/lib
        ${CMAKE_SOURCE_DIR}/lib/3rd/${BUILD_PLATFORM}/lib
)

target_link_libraries(${PROJECT_NAME} serial common__rosidl_typesupport_cpp opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")

install(TARGETS ${PROJECT_NAME}
        ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib/product/${BUILD_PLATFORM}/
        LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/lib/product/${BUILD_PLATFORM}/
)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
        COMMAND ${STRIP_CMD} $<TARGET_FILE:${PROJECT_NAME}>
        COMMAND ${CMAKE_COMMAND} --build . --target install
        COMMENT "Installing and stripping ${PROJECT_NAME}"
    )